package com.newbie.pet.model;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

import static javax.persistence.GenerationType.AUTO;

/**
 * 类描述：公共参数
 *
 * @author zhangkailiang
 * @date 2020/5/23
 */
@Data
@MappedSuperclass
public class BaseEntity {

    @NotNull
    @ApiModelProperty(value = "Id")
    @Id
    @GeneratedValue(strategy = AUTO)
    private Long id;

    @ApiModelProperty(value = "创建时间")
    private Date createDate;

    @ApiModelProperty(value = "修改时间")
    private Date updateDate;

    @PrePersist
    public void createDate() {
        Date date = new Date();
        this.createDate = date;
        this.updateDate = date;
    }

    @PreUpdate
    public void setUpdateDate() {
        this.updateDate = new Date();
    }
}
